<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="easyui-layout" style="width:100%;height:100%;" fit="true">
    <div data-options="region:'center',title:'',split:true" style="height:100%;">
		<form id="brandInfoForm" method="post" >
			<table class="detailTable"> 
    	 	<tr>
                <th>品牌中文:</th> 
                <td>
                   <input class="easyui-validatebox " id="brandChsName" name="brandChsName" style="width:400px;" data-options="required:true">
                   <input type="hidden" id="brandId" name="brandId" data-options="required:true">
                </td>
            </tr>
            <tr>
                <th>品牌英文:</th>
                <td><input class="easyui-validatebox " id="brandEngName" name="brandEngName" style="width:400px;" data-options="validType:'english'"></td>
            </tr>
             
            <tr>
                <th>品牌拼音:</th>
                <td><input class="easyui-validatebox" id="brandSpell"name="brandSpell" style="width:400px;" data-options="validType:'english'"></td>
            </tr>
            <tr>
            <th>品牌logo:</th>
					<td>
						<span id="smallPicName">
						</span>
						<input type="hidden" id="smallPic" name="smallPic">
						<input type="hidden" id="uploadId" name="uploadId">
						<a class="easyui-linkbutton" href="javascript:uploader();">logo上传</a>
					</td>
            </tr>
            <tr>
                <th>官网地址:</th>
                <td><input class="easyui-validatebox " id="siteUrl" name="siteUrl" style="width:400px;" data-options="validType:'url'"></td>
            </tr>
            <tr>
                <th>品牌描述:</th>
                <td>
                   <textarea id="brandDesc" name="brandDesc" rows="2" cols="60"></textarea>
                </td>
            </tr>
            <tr>
                <th>是否正常:</th>
                <td>
                    <input type="radio" id="isShow" name="isShow" value="1" checked="checked">正常
				    <input type="radio" id="isShow" name="isShow" value="0" >删除
                </td>
            </tr>
            <tr>
				<th>排序:</th>
				<td><input class="easyui-numberspinner" name="sortOrder" value="0" style="width: 70px;"></td>
			</tr>
			 <%
	        String onViewFlag = request.getParameter("onViewFlag");
	        onViewFlag=onViewFlag==null?"":onViewFlag;
	        if(onViewFlag.equals("")){
	        %>
            <tr>
			    <th>操作：</th>
				<td align="center" > 
					<input type="button" onclick="submitForm()" class="button" value="提交" >
					<input type="button" onclick="pms.resetForm('brandInfoForm')" class="button" value="重置" >
				    <!-- <input type="button" onclick="test()" class="button" value="测试" >    -->      
				</td>
			</tr>
            <%} %>
			
		</table>
		</form>
    </div>
</div>  
<script>
//标示 0：save方法，1：update方法
var flag =0; 
$(function(){
	var brandId="<%=request.getParameter("code")%>";
	if(brandId!="null"){	//save	
		flag = 1;
		var param = {"brandId":brandId};
 		$.pmsAjax({
			url:'<c:url value="/brand/showEmBBrandDetail.do"/>',
			data:param,
			success:function(data){
				var emBBrand = data.data.emBBrand;	
				//console.log(emBBrand);
				if(data.code=="200"){
					//alertShow("成功");
					$('#brandInfoForm').form('load', emBBrand);
					if(emBBrand.smallPic){
						$("#smallPicName").html("<img src='"+contentPath+emBBrand.smallPic+"' width='30px;' height='30px;' />");
					}
					
				}else{
					alertError(data.result);
				}	
			}
		});
	}
})
function submitForm(){
	if(flag == 0){
		doInsert();
	}else{
		doUpdate();
	}	
}
//insert
function doInsert(){
	$('#brandInfoForm').form('submit', {
		url:'<c:url value="/brand/insertEmBBrand.do"/>',
	    onSubmit: function(param){
	    	if(!$("#brandInfoForm").form('validate')){
	    		return false;
	    	}
	    }, 
	    success:function(data){
		    var ret = eval("("+data+")");
	     	if(ret.code=='200'){
	     		alertShow("新增成功");
	     		brandsTable.refresh();
	     		$("#w_brand_detail").dialog('close');
		    }else{
		    	parent.alertError(ret.result);
			}
	    }
	});
}
//update
function doUpdate(){
	$('#brandInfoForm').form('submit', {
	    url:'<c:url value="/brand/updateEmBBrand.do"/>',
	    onSubmit: function(param){
	    	if(!$("#brandInfoForm").form('validate')){
	    		return false;
	    	}
	    }, 
	    success:function(data){
		    var ret = eval("("+data+")");
	     	if(ret.code=='200'){
	     		alertShow("修改成功");
	     		brandsTable.refresh();
	     		$("#w_brand_detail").dialog('close');
	     		
		    }else{
		    	alertError(ret.result);
			}
	    }
	});
}
function test(){
	$("#brandChsName").val("测试品牌");
	$("#brandEngName").val("brandEngName");
	$("#brandSpell").val("brandSpell");
	$("#siteUrl").val("www.baidu.com");
	$("#brandDesc").val("新增品牌");
	
	}
function  uploader(){
	$.pmsDialog({
		id:"plug_upload",  //固定ID
		title:'选择品牌logo',
		isIf:'true',
		params:{    //这4个必须填   可
    		"fileType":"img", //必填项  file  orimg
    		"oneSelect":'true',
    		"moduleId":"product",
    		"funcId":"brand",
    		"dataId":""
    	},
		method:'post',
		href:'<c:url value="/views/jsp/upload/com_uploader_s.jsp"/>',
		width:600,
		height:464
	});
}
function getFiles(obj){
	if(obj!='undefined'){
		$('#smallPicName').html("<img src='"+contentPath+obj[0].relativeFilePath+"small_"+obj[0].fileSysName+"' width='30px;' height='30px;' />");
		$('#smallPic').val(obj[0].relativeFilePath+"small_"+obj[0].fileSysName);
		$('#uploadId').val(obj[0].id);
		alertShow("选择图片成功!");
	}
}
</script>
